package demo;

import com.jfinal.kit.PropKit;
import com.jfinal.plugin.IPlugin;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.PostgreSqlDialect;
import com.jfinal.plugin.druid.DruidPlugin;

/**
 * Created by Administrator on 2016/11/2 0002.
 */
public class JfinalConfig {

    public static IPlugin plugin;

    public static void start() {
        if (plugin == null) {

            configConstant();
            String url = PropKit.get("jdbc.url", "jdbc:postgresql://localhost:5432/child_spring");
            String user = PropKit.get("jdbc.username", "postgres");
            String pass = PropKit.get("jdbc.password", "postgresql");
            DruidPlugin dp = new DruidPlugin(url, user, pass);
            ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
            arp.setShowSql(true);
            arp.setDialect(new PostgreSqlDialect());
            plugin = dp;

            dp.start();
            arp.start();
        }

    }

    private static void configConstant() {
        PropKit.use("init.properties");
    }

}
